UserCreationForm {django}

0014.1 Django 🎈에서 회원가입 폼을 만들 때 사용한 클래스를 한 번 보자. 이메일은 기본으로 제공이 안되어 내가 추가한 걸 볼 수 있는데, Meta 얘는 도대체 뭐냐?

from django import forms
from django.contrib.auth.models import User
from django.contrib.auth.forms import UserCreationForm


class UserRegisterForm(UserCreationForm):
    """pre-built user registration forms.... SICK!"""
    email = forms.EmailField()

    class Meta:
        """details"""
        model = User
        fields = ['username', 'email', 'password1', 'password2']

모델의 메타데이터를 정의한다. 메타데이터란, 필드가 아닌 모든 모델을 정의하는 데이터들을 의미한다.

Model metadata is “anything that’s not a field”, such as ordering options (ordering), database table name (db_table), or human-readable singular and plural names (verbose_name and verbose_name_plural). None are required, and adding class Meta to a model is completely optional.

Model Meta

https://docs.djangoproject.com/en/4.1/ref/models/options/

Form Meta

https://docs.djangoproject.com/en/4.1/ref/forms/fields/